from pathlib import Path


def save_order_to_file(order_path, name, content, money):
    if not Path(order_path).exists():
        print('文件不存在,已自动创建')

    order = Path(order_path).open('a', encoding='utf-8')
    order.write(f'客户姓名{name},订单内容{content},订单金额{money}\n')


def read_order(order_path):
    if not Path(order_path).exists():
        print('当前没有订单')
        return
    print(Path(order_path).read_text(encoding='utf-8'))


def run():
    order_path = './order.txt'
    while True:
        print('1.保存订单')
        print('2.读取订单')
        print('3.退出')
        choice = input('选择操作:')
        if choice == '1':
            name = input('请输入客户姓名:')
            content = input('请输入订单内容:')
            money = input('请输入订单金额:')
            save_order_to_file(order_path, name, content, money)
        elif choice == '2':
            read_order(order_path)
        else:
            break

    # save_order_to_file(order_path, '张三', '红烧肉', 100)
    # save_order_to_file(order_path, '李四', '红烧肉', 100)
    # read_order(order_path)


if __name__ == '__main__':
    run()
